package com.ancun;

import ancun.seal.servlet.SealClient;
import ancun.seal.util.FileUtil;
import ancun.seal.util.StringUtil;

import org.junit.Test;

import java.io.File;

/**
 * 普通制章
 * 
 */
public class MakeSealTest extends ServletBaseTest{

//    public MakeSealTest() throws Exception {
//        makeSealTest();
//    }
    @Test
    public void makeSealTest() throws Exception {
        /** HTTP方式 */
        String url = super.url + SealClient.SLASH + SealClient.MAKE_SEAL_SERVLET;
        SealClient sealClient = new SealClient(url);
        //指定pfx路径
        String pfxPath = super.baseSources + "szca_pem_898608.pfx";
        byte[] pfx = FileUtil.getBytesFromFile(new File(pfxPath));
        //指定pfx密码
        String pfxPasswd = "898608";
        String imagePath = super.baseSources + "222.png";
        byte[] image = FileUtil.getBytesFromFile(new File(imagePath));

        String sealPerson = "江苏江南农村商业银行股份有限公司江苏江南农村商业银行";
        String sealOrg = "江苏江南农村商业银行股份有限公司";
        String sealName = "江苏江南农村商业银行股份有限公司";
        String sealCode = "cfca_3_1543453841324";
        String sealPassword = "123456";
        // 印章类型0：企业 1：个人
        String sealType = "1";
        String imageCode = "10012";
        String orgCode = "root";

        String sealInfoXML = "<Request>" + "<SealPerson>" + sealPerson + "</SealPerson>" + "<SealOrg>" + sealOrg + "</SealOrg>" + "<SealName>" + sealName
                + "</SealName>" + "<SealCode>" + sealCode + "</SealCode>" + "<SealType>" + sealType + "</SealType>" + "<SealPassword>" + sealPassword
                + "</SealPassword>" + "<ImageCode>" + imageCode + "</ImageCode>" + "<OrgCode>" + orgCode + "</OrgCode>" + "</Request>";

        long time1 = System.currentTimeMillis();
        String result = sealClient.makeSeal(pfx, pfxPasswd, image, sealInfoXML);
        System.out.println("result= " + result);
        long time2 = System.currentTimeMillis();
        System.out.println("Time: " + (time2-time1));
        System.out.println(result);
        if ("200".equals(StringUtil.getNodeText(result, "Code"))) {
            System.out.println("com.ancun.MakeSealTest(Servlet):ok");
        } else {
            System.out.println("com.ancun.MakeSealTest(Servlet):wrong");
        }
    }

}
